#pragma once
#include <QCoreApplication>

#include <open62541/server_config_default.h>
#include <open62541/plugin/accesscontrol_default.h>
#include <open62541/client_highlevel.h>
#include <open62541/plugin/log_stdout.h>
#include <open62541/plugin/securitypolicy.h>
#include <open62541/server.h>
#include <open62541/server_config_default.h>

#include <stdlib.h>

#include "common.h"

#include <QThread>


/* This is a test server to the ci script. It can be used for some of the examples that need a server to connect.
* It allows to connect with the username "peter" and "paula" and the password "peter123" and "paula123" or "user1" and "password". Anonymus login is also allowed.
* The server has a method "hello world" and a variable "the answer" that can be written to.
* The server certificate and private key are loaded from the command line arguments.
*/

#define MIN_ARGS 4


typedef UA_StatusCode (*CallbackFunc)(UA_Server *server,
                             const UA_NodeId *sessionId, void *sessionHandle,
                             const UA_NodeId *methodId, void *methodContext,
                             const UA_NodeId *objectId, void *objectContext,
                             size_t inputSize, const UA_Variant *input,
                             size_t outputSize, UA_Variant *output);

//typedef std::function<UA_StatusCode(UA_Server *,
//                                    const UA_NodeId *,void *,
//                                    const UA_NodeId *,void *,
//                                    const UA_NodeId *,void *,
//                                    size_t,const UA_Variant *,
//                                    size_t , UA_Variant *)> CallbackFunc;


class Open62541Server:public QThread
{
    Q_OBJECT
public:
    Open62541Server(char* inputName,char *outputName,CallbackFunc callbackFunc){

        _inputName = inputName;
        _outputName = outputName;
        _callbackFunc = callbackFunc;
    }

public:


protected:
    void run() override;

    int server_start();


private:
    UA_Server *_server  = nullptr;

    char *_inputName = nullptr;
    char *_outputName = nullptr;
    CallbackFunc _callbackFunc;
};
